package com.fxp.project.jiuselu.web.business.v1.controller.user;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fxp.project.jiuselu.web.base.controller.BaseController;
import com.fxp.project.jiuselu.web.domain.CommonResult;
import com.fxp.project.jiuselu.web.models.user.entity.JslCompanyProfile;
import com.fxp.project.jiuselu.web.models.user.service.IJslCompanyProfileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/v1/user/profile")
public class JslCompanyProfileController extends BaseController {
    @Autowired
    IJslCompanyProfileService companyProfileService;

    /**
     * 查询公司简介
     * 列表
     */
    @GetMapping("/list")
    @CrossOrigin
    public CommonResult list(JslCompanyProfile companyProfile) {
        List<JslCompanyProfile> list = companyProfileService.list(new QueryWrapper<>(companyProfile));
        return CommonResult.success(list);
    }
    /**
     * 获取公司简介
     * 详细信息
     */
    @PostMapping(value = "/{id}")
    @CrossOrigin
    public CommonResult getInfo(@PathVariable("id") Long id) {
        return CommonResult.success(companyProfileService.getById(id));
    }

    /**
     * 新增公司简介
     */
    @PostMapping
    @CrossOrigin
    public CommonResult add(@RequestBody JslCompanyProfile companyProfile) {
        return CommonResult.success(companyProfileService.save(companyProfile));
    }

    /**
     * 修改公司简介
     */
    @PutMapping
    @CrossOrigin
    public CommonResult edit(@RequestBody JslCompanyProfile companyProfile) {
        return CommonResult.success(companyProfileService.updateById(companyProfile));
    }

    /**
     * 删除公司简介
     */
    @DeleteMapping("/{ids}")
    @CrossOrigin
    public CommonResult remove(@PathVariable Long[] ids) {

        return CommonResult.success(companyProfileService.removeByIds(Arrays.asList(ids)));
    }
}
